﻿@using OBUCare.Web.Infrastructure
@using OBUCare.Core.BL
@using OBUCare.Core.DataAccess;
@using OBUCare.Web.Models;
@using OBUCare.Core.Common;
@{
    ObuDropDownListHlper ddlHelper = new ObuDropDownListHlper();


    var operatorInfo = UIUtility.GetCurrentUser();

    var menuNames = ViewData["menuName"];

    string AgentNo = UIUtility.getAgentByModule(operatorInfo, menuNames.ToString());
}
@using (Html.BeginForm("PartsSaleSearch", "PartsReport", FormMethod.Post, new { @id = "searchForm" }))
{

    <table style="width: 100%">
        <tr>
            <td style="width: 10%; text-align: right; height: 40px;">
                销售日期起：
            </td>
            <td style="width: 20%; text-align: left;">
                @Html.Telerik().DatePicker().Name("FromCreatedDate").HtmlAttributes(new { @style = "Width:170px;" }).OpenOnFocus(true).ShowButton(false).Value(DateTime.Now.ToShortDateString())
            </td>
            <td style="width: 10%; text-align: right">
                销售日期止：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.Telerik().DatePicker().Name("ToCreatedDate").HtmlAttributes(new { @style = "Width:170px;" }).OpenOnFocus(true).ShowButton(false).Value(DateTime.Now.ToShortDateString())
            </td>
            <td align="right" width="10%">
                元器件：
            </td>
            <td align="left" width="30%">
                @Html.Telerik().DropDownList().Name("PartType").BindTo(ddlHelper.GetPartTypes(UIConstants.AllItems, true, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems)))
            </td>
        </tr>
        <tr style="height: 40px;">
            <td align="right">
                厂商：
            </td>
            <td align="left">
                @Html.Telerik().DropDownList().Name("Supplier").BindTo(ddlHelper.GetSuppliers(UIConstants.AllItems, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems))).ClientEvents(e => e.OnChange("changeSpecs"))
            </td>
            <td align="right">
                型号：
            </td>
            <td align="left">
                @Html.Telerik().DropDownList().Name("SpecName").BindTo(ddlHelper.GetPartsSpecs(null, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems)))
            </td>
            <td align="right">
                营业厅类别：
            </td>
            <td align="left">
                @Html.Telerik().DropDownList().Name("AgentType").BindTo(ddlHelper.GetAgentTypes(UIConstants.AllItems, false, AgentNo, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems))).CascadeTo("Agent")
            </td>
        </tr>
        <tr style="height: 40px;">
            <td align="right">
                营业厅：
            </td>
            <td align="left">
                @*                @Html.Telerik().DropDownList().Name("Agent").HtmlAttributes(new { @style = "Width:230px;" }).ClientEvents(events => events.OnLoad("agentonload")).SelectedIndex(AgentNo == "" ? 0 : 1)*@
                @Html.Telerik().DropDownList().Name("Agent").DataBinding(binding => binding.Ajax().Select("_GetAgent", "RepairOrders", new { AgentNo = AgentNo }))
            </td>
            <td align="right">
                操作员：
            </td>
            <td align="left">
                @Html.Telerik().DropDownList().Name("Operator").BindTo(ddlHelper.GetOPERATORSByAgentNo(menuNames, UIConstants.AllItems, AgentNo, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems)))
            </td>
            <td style="text-align: right;">
                标签号：
            </td>
            <td style="text-align: left">
                @Html.TextBox("ObuNo", "", new { @style = "width:138px;height:15px", @MaxLength = 20 })
                (至少后六位)
            </td>
        </tr>
        <tr>
            <td style="text-align: right;">
                销售金额：
            </td>
            <td style="text-align: left">
                @Html.TextBox("Amount", "", new { @style = "width:138px;height:15px", @MaxLength = 20 })
            </td>
            <td colspan="2">
            </td>
            <td colspan="2" align="center">
                <input type="button" value="查询" id="btnSearch" />
                @Html.Hidden("searchSql", "", new { @id = "searchSql" })
                @Html.Hidden("agentNO", AgentNo, new { @id = "agentNO" })
                @Html.Hidden("menuNames", menuNames, new { @id = "menuNames" })
            </td>
        </tr>
    </table>
    
    
}
<script type="text/javascript">

    $().ready(function () {

        $('#btnSearch').click(function () {
            search();
        });

        @*if ("@agentNO".length != 0) {
            var agentType = $('#AgentType').data('tDropDownList');
            var transferBillStatus = $('#TransferBillStatus').data('tDropDownList');
            agentType.select(1); agentType.disable();
        }*@
    });


    function search() {
    if( $.trim($('#FromCreatedDate').val())=="" ||  $.trim($('#ToCreatedDate').val())=="")
    {
       alert("请输入完整日期");
       return false;
    }
        var form = $("#searchForm");
        dataString = form.serialize();
        $.ajax({
            type: "POST",
            url: form.attr('action'),
            data: dataString,
            cache: false,
            dataType: "json",
            success: function (data) {

                if (data.Success) {
                    //alert('成功');
                    //debugger;
                    var grid = $('#Grid').data('tGrid')
                    $('#searchSql').val(data.Sql)
                    grid.rebind();
                }
                else {
                    alert('失败：' + data.ErrorMsg)
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                var err = XMLHttpRequest + "<br />" + textStatus + "<br />" + errorThrown;
                alert(err);
            }
        });
    }

    function changeSpecs(e)
    {
       var SpecName = $('#SpecName').data('tDropDownList');
        var value = e.currentTarget.value;
        $.post("/PartsReport/getSpecs", { "supplierID": value}, function (data) {
            SpecName.dataBind(data);
            if (SpecName != null) {
                SpecName.select(0);
            }
        });
    }

</script>
@{
    ddlHelper.Dispose();    
}
